import VueRouter from "vue-router";
import Vue from "vue";
import store from "./store";

import Home from "../pages/index/Index.vue";
import Login from "../pages/login/Login.vue";
import Menu from "../pages/menu/Index.vue";
import Org from "../pages/org/Index.vue";
import OrgDetail from "../pages/org/Detail.vue";
import OrgDetailManager from "../pages/org/detail/Manager.vue";
import User from "../pages/user/Index.vue";
import UserDetail from "../pages/user/Detail.vue";
import UserLoan from "../pages/user/detail/Loan.vue";
import UserMoneyLog from "../pages/user/detail/MoneyLog.vue";
import UserCallLog from "../pages/user/detail/CallLog.vue";
import UserTicketLog from "../pages/user/detail/TicketLog.vue";
import UserKyc from "../pages/user/detail/Kyc.vue";
import UserWithdraw from "../pages/user/Withdraw.vue";
import UserDeposit from "../pages/user/Deposit.vue";
import Loan from "../pages/loan/Index.vue";
import LoanTag from "../pages/loan/tag/Index.vue";
import LoanImport from "../pages/loan/Import.vue";
import LoanDetail from "../pages/loan/Detail.vue";
import LoanDetailComment from "../pages/loan/detail/Comment.vue";
import LoanCallLog from "../pages/loan/detail/CallLog.vue";
import AppUser from "../pages/app/User.vue";


import WebsiteCity from "../pages/website/city/index.vue";
import WebsiteManage from "../pages/website/manage/index.vue";
import WebsiteAbout from "../pages/website/manage/About.vue";
import WebsiteUser from "../pages/website/user/index.vue";
import WebsiteStore from "../pages/website/store/index.vue";
import WebsiteQa from "../pages/website/qa/index.vue";
import WebsiteNews from "../pages/website/news/index.vue";
import WebsiteCase from "../pages/website/cases/index.vue";
import WebsiteScheme from "../pages/website/scheme/index.vue";


import AppSetting from "../pages/app/Setting.vue";
import H5Setting from "../pages/h5/Setting.vue";
import AppQa from "../pages/app/Qa.vue";
import AppBanner from "../pages/app/setting/Banner.vue";
import AppPrivacy from "../pages/app/setting/Privacy.vue";
import AppLicense from "../pages/app/setting/License.vue";
import AppRules from "../pages/app/setting/Rules.vue";
import AppQrCode from "../pages/app/setting/QrCode.vue";
import AppQaCreate from "../pages/app/qa/Create.vue";
import ChatHome from "../pages/chat/Home.vue";
import ChatRoom from "../pages/chat/Room.vue";
import AppSetCityAmount from "../pages/app/setting/SetCityAmount.vue";
import H5Diy from "../pages/app/setting/H5Diy.vue";
import WEBDiy from "../pages/app/setting/WEBDiy.vue";
import AppDataStatistics from "../pages/app/setting/DataStatistics.vue";


Vue.use(VueRouter);

const routes = [
    {
        path: "/",
        component: Home,
        name: "home",
    },
    {
        path: "/login",
        component: Login,
        name: "login",
        meta: {
            layout: 'default'
        }
    },
    {
        path: "/menu",
        component: Menu,
        name: "menu",
    },
    {
        path: "/org",
        component: Org,
        name: "org",
    },
    {
        path: "/org/:id",
        component: OrgDetail,
        children: [
            { path: '', component: OrgDetailManager }
        ],
    },
    {
        path: "/user",
        component: User,
        name: "user",
    },
    {
        path: "/user/:id",
        component: UserDetail,
        children: [
            { path: '', component: UserLoan },
            { path: 'money', component: UserMoneyLog },
            { path: 'kyc', component: UserKyc },
            { path: 'call', component: UserCallLog },
            { path: 'ticket', component: UserTicketLog },
        ],
    },
    {
        path: "/loan",
        component: Loan,
        name: "loan",
    },
    {
        path: "/withdraw",
        component: UserWithdraw,
        name: "withdraw",
    },
    {
        path: "/deposit",
        component: UserDeposit,
        name: "deposit",
    },
    {
        path: "/loan-tag",
        component: LoanTag,
        name: "loan-tag",
    },
    {
        path: "/loan/import/:category",
        component: LoanImport,
        name: "loan-import",
    },
    {
        path: "/loan/:id",
        component: LoanDetail,
        children: [
            { path: '', component: LoanDetailComment },
            { path: 'call', component: LoanCallLog }
        ],
    },
    {
        path: "/website/city",
        component: WebsiteCity,
        name: "website-city",
    },
    {
        path: "/website/manage",
        component: WebsiteManage,
        name: "website-manage",
        children: [
            { path: '', component: WebsiteAbout },
        ]
    },
    {
        path: "/website/user",
        component: WebsiteUser,
        name: "website-user",
    },
    {
        path: "/website/store",
        component: WebsiteStore,
        name: "website-store",
    },
    {
        path: "/website/qa",
        component: WebsiteQa,
        name: "website-qa",
    },
    {
        path: "/website/news",
        component: WebsiteNews,
        name: "website-news",
    },
    {
        path: "/website/cases",
        component: WebsiteCase,
        name: "website-case",
    },
    {
        path: "/website/scheme",
        component: WebsiteScheme,
        name: "website-scheme",
    },




    {
        path: "/h5/setting",
        component: H5Setting,
        name: "H5-news",
    },




    {
        path: "/app/user",
        component: AppUser,
        name: "app-user",
    },
    {
        path: "/app/user/:id",
        component: UserDetail,
        children: [
            { path: '', component: UserLoan },
            { path: 'money', component: UserMoneyLog },
            { path: 'kyc', component: UserKyc },
            { path: 'call', component: UserCallLog },
            { path: 'ticket', component: UserTicketLog },
        ],
    },
    {
        path: "/app/setting",
        component: AppSetting,
        name: "app-setting",
        children: [
            { path: '', component: AppBanner },
            { path: 'privacy', component: AppPrivacy },
            { path: 'license', component: AppLicense },
            { path: 'rules', component: AppRules },
            { path: 'qr_code', component: AppQrCode },
            { path: 'set_city_amount', component: AppSetCityAmount },
            { path: 'h5_diy', component: H5Diy },
            { path: 'web_diy', component: WEBDiy },
            { path: 'data_statistics', component: AppDataStatistics },
        ],
    },
    {
        path: "/app/qa",
        component: AppQa,
        name: "app-qa",
    },
    {
        path: "/app/qa/create",
        component: AppQaCreate,
        name: "app-qa-create",
    },
    {
        path: "/app/qa/edit/:id",
        component: AppQaCreate,
        name: "app-qa-edit",
    },
    {
        path: "/chat",
        component: ChatHome,
        name: "chat",
        children: [
            { path: '', redirect: 'room/0' },
            {
                path: 'room/:id', component: ChatRoom, meta: {
                    layout: 'chat'
                }
            }
        ],
    },
];

const router = new VueRouter({
    mode: 'hash',
    routes,
    /* eslint-disable no-unused-vars */
    scrollBehavior(to, from, savedPosition) {
        // return 期望滚动到哪个的位置
        if (savedPosition) {
            return savedPosition;
        } else {
            return { x: 0, y: 0 };
        }
    }
});

/* eslint-disable no-unused-vars */
router.beforeEach((to, from, next) => {
    next();
});


/* eslint-disable no-unused-vars */
router.afterEach((to, from) => {
    if (to.meta && typeof to.meta.layout !== 'undefined') {
        store.commit("layout", to.meta.layout);
    } else {
        store.commit("layout", 'dashboard');
    }
})

export default router;
